package com.example.select3;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        ListView listview1 = findViewById(R.id.listview1);

        BaseAdapter adapter = new PlantSelectAdapter(this,Plant.getDefaultPlants());
        listview1.setAdapter(adapter);
        listview1.setSelected(true);
        listview1.setSelection(0);
        listview1.setActivated(true);
        listview1.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

        listview1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TextView title = view.findViewById(R.id.title);
                Toast.makeText(MainActivity2.this,title.getText().toString(),Toast.LENGTH_SHORT).show();
            }
        });

    }
}